Hello! |
Re: Temp Skip Lists You will have to iterate through the contents of your skip list and add the items individually or keep the skip lists global and creaet more as you need them. This sort of data structure can get very confusing and error prone - what is it you are trying to do? There may be a better solution. |
Re: Temp Skip Lists Well, I thought about putting evrything in a global skip list the only problem is that the elements I get from the module have basically the name name and I use string keys. That is to say the structure is of this type: <element1> <type1> <name1> <value> <value/> <name1/> <name2> <value> <value/> <name2/> .... <type1/> <type2> <name1> <value> <value/> <name1/> <name2> <value> <value/> <name2/> .... <type2/> ... <element1/> Since name1 and name2 are often the same, I created a temp Skip List that took {"type1" : value, "name1": value, "name2": value} One loop fills the temp Skip List for an "element" and put it (or I want to put it) in something else that store data on all elements. My purpose is to make of a block of text something that you can parse (XML like) since data is for the moment pure text (which still has some patterns that I try to parse) Any idea ? |
Re: Temp Skip Lists Well, I thought about putting evrything in a global skip list the only problem is that the elements I get from the module have basically the name name and I use string keys. That is to say the structure is of this type: <element1> <type1> <name1> <value> <value/> <name1/> <name2> <value> <value/> <name2/> .... <type1/> <type2> <name1> <value> <value/> <name1/> <name2> <value> <value/> <name2/> .... <type2/> ... <element1/> Since name1 and name2 are often the same, I created a temp Skip List that took {"type1" : value, "name1": value, "name2": value} One loop fills the temp Skip List for an "element" and put it (or I want to put it) in something else that store data on all elements. My purpose is to make of a block of text something that you can parse (XML like) since data is for the moment pure text (which still has some patterns that I try to parse) Any idea ? |
Re: Temp Skip Lists
As Tony said, you have to be extra careful when creating nested skip lists, i.e. skip lists which have skip lists as values. To start with, deleting the "outer" skip list does not free the memory of the inner skip lists, thus you must explicitly delete the inner skip lists to avoid memory leaks. Secondly, it is extra easy to get ACCESS VIOLATION errors, as you already experienced. In your case, deleting the tempSkip in the main loop and then accessing it from Skip 2 was the key to the error, as, again as Tony said, only the address to the skip list is stored.
Skip globalList
void deleteSkip(Skip sList)
{ // Delete nested skip list and free memory
Skip s
for s in sList do {delete s}
delete sList
} // Delete nested skip list and free memory
void addSkip(int iGlobKey)
{ // Put a local skip list into the global variable
Skip localList = create
int nValue = random(5) + 1
int i
for i in 0:nValue - 1 do
{ // Create a local skip list
put(localList, i, "A random number: " (random 100) "")
} // Create a local skip list
put(globalList, iGlobKey, localList)
// Do no delete the localList here, as this would result in
// EXCEPTION_ACCESS_VIOLATION errors when you try to access them via
// the global skip list later
} // Put a local skip list into the global variable
void printAllValues()
{ // Print all values from all stored skip lists
// You must be very careful here that the data types used as keys
// and values in the local and global skip list during creation match the
// ones used here
Skip localList
int iKey, iGlobalKey
string sValue
for localList in globalList do
{ // Loop hrough local skip lists
iGlobalKey = (int key globalList)
for sValue in localList do
{ // Loop through local Lists's values
iKey = (int key localList)
print ""//
"Global key : " iGlobalKey " | "//
"Local key : " iKey " | "//
"Local value : " sValue "\n"
} // Loop through local Lists's values
} // Loop hrough local skip lists
} // Print all values from all stored skip lists
// Main
globalList = create()
addSkip(1)
addSkip(2)
printAllValues()
deleteSkip(globalList)
|
Re: Temp Skip Lists Peter_Albert - Tue Jun 09 10:06:17 EDT 2009
As Tony said, you have to be extra careful when creating nested skip lists, i.e. skip lists which have skip lists as values. To start with, deleting the "outer" skip list does not free the memory of the inner skip lists, thus you must explicitly delete the inner skip lists to avoid memory leaks. Secondly, it is extra easy to get ACCESS VIOLATION errors, as you already experienced. In your case, deleting the tempSkip in the main loop and then accessing it from Skip 2 was the key to the error, as, again as Tony said, only the address to the skip list is stored.
Skip globalList
void deleteSkip(Skip sList)
{ // Delete nested skip list and free memory
Skip s
for s in sList do {delete s}
delete sList
} // Delete nested skip list and free memory
void addSkip(int iGlobKey)
{ // Put a local skip list into the global variable
Skip localList = create
int nValue = random(5) + 1
int i
for i in 0:nValue - 1 do
{ // Create a local skip list
put(localList, i, "A random number: " (random 100) "")
} // Create a local skip list
put(globalList, iGlobKey, localList)
// Do no delete the localList here, as this would result in
// EXCEPTION_ACCESS_VIOLATION errors when you try to access them via
// the global skip list later
} // Put a local skip list into the global variable
void printAllValues()
{ // Print all values from all stored skip lists
// You must be very careful here that the data types used as keys
// and values in the local and global skip list during creation match the
// ones used here
Skip localList
int iKey, iGlobalKey
string sValue
for localList in globalList do
{ // Loop hrough local skip lists
iGlobalKey = (int key globalList)
for sValue in localList do
{ // Loop through local Lists's values
iKey = (int key localList)
print ""//
"Global key : " iGlobalKey " | "//
"Local key : " iKey " | "//
"Local value : " sValue "\n"
} // Loop through local Lists's values
} // Loop hrough local skip lists
} // Print all values from all stored skip lists
// Main
globalList = create()
addSkip(1)
addSkip(2)
printAllValues()
deleteSkip(globalList)
This looks right. Yes, the local Skips are stored not a copy of them.
//***********************
void fSkipDelSkip(Skip &skpIn)
{ // Delete the Skip list, first deleting all the 'Skip' list DATA elements.
// Be sure the Skip's DATA is type 'Skip'.
if (null skpIn) return
Skip skpData
for skpData in skpIn do
{ delete(skpData)
}
delete(skpIn)
} // end fSkipDelSkip()
|
Re: Temp Skip Lists Thanks for your answers ! Indeed, this might be helpful, I think that was what I was looking for. Again, thank you! Regards. |